﻿/// <reference path="../game/fourkill.util.js" />
/// <reference path="../input/init.fourkill.input.base.js" />
/// <reference path="../input/fourkill.input.tap.js" />
/// <reference path="../input/post.fourkill.input.singletons.js" />

var GpsTestsView_Tap = Base.extend({
    initialize: function initialize() {
        this.queue = [];
        this.enabled = false;
    },
    isAvailable: function isAvailable() {
        return true;
    },
    enable: function enable() {
        if (!this.enabled && GlobalInputHandlers.Tap.isAvailable() && GlobalInputHandlers.Tap.enabled) {
            this.enabled = true;
            var self = this;
            GlobalInputHandlers.Tap.subscribe("GpsTestsView.Tap", self);
        }
    },
    disable: function disable() {
        if (this.enabled) {
            this.enabled = false;
            GlobalInputHandlers.Tap.unsubscribe("GpsTestsView.Tap");
        }
    },
    fireEvent: function fireEvent(eventName, data) {
        if (eventName == "vclick") {
            if (!isNaN(data.clientX) && !isNaN(data.clientY)) {
                this.queue.push({ x: data.clientX, y: data.clientY });         // queue is now [2]
                if (data.prevent) data.preventDefault();
            }
        }
    },
    update: function update(context) {
        context.tapped = this.queue.length > 0;
        if (context.tapped) {
            var p = this.queue.shift();
            context.x =  p.x;
            context.y = p.y;
        }
    }
});
